/**
 * @param {number[]} nums1
 * @param {number} m
 * @param {number[]} nums2
 * @param {number} n
 * @return {void} Do not return anything, modify nums1 in-place instead.
 */
var merge = function(nums1, m, nums2, n) {
  let arr = [...nums1], index = 0, i = 0, j = 0;
  while(i < m && j < n) {
    if(nums1[i] <= nums2[j])
      arr[index++] = nums1[i++];
    else
      arr[index++] = nums2[j++];
  }
  while(i < m)
    arr[index++] = nums1[i++];
  while(j < n)
    arr[index++] = nums2[j++];
  for(let i = 0; i < nums1.length; i++) {
    nums1[i] = arr[i];
  }
  return nums1;
};
let nums1 = [1,2,3,0,0,0], m = 3, nums2 = [2,5,6], n = 3;
console.log(merge(nums1, m, nums2, n));
nums1 = [1], m = 1, nums2 = [], n = 0;
console.log(merge(nums1, m, nums2, n));
nums1 = [0], m = 0, nums2 = [1], n = 1;
console.log(merge(nums1, m, nums2, n));
